<?php

namespace app\command;

use app\model\table\log\OperateLog;
use app\model\table\talk\Talk;
use think\console\Command;
use think\console\Input;
use think\console\Output;


/**
 * @title 定时任务
 */
class commandClearDataBase extends Command
{
    protected function configure()
    {
        $this->setName('commandClearDataBase')->setDescription("计划任务 commandClearDataBase");//
    }

    /**
     *   工会赛季排行榜
     */
    protected function execute(Input $input, Output $output)
    {
        $this->clearLog();
        $this->clearTalk();
        $output->writeln('success');
    }

    private function clearLog()
    {
        $day = date('Y-m-d', strtotime('-30 days'));
        OperateLog::instance()->where("created_at",'<=', $day)->delete();
    }

    private function clearTalk()
    {
        $day = date('Y-m-d', strtotime('-30 days'));
        Talk::instance()->where("created_at",'<=', $day)->delete();
    }
}
